import pygame


class Ship:
    # def __init__(self, settings, screen):
    def __init__(self, **kwargs):
        settings = kwargs.get('settings')
        screen = kwargs.get('screen')
        self.screen = screen
        # 加载配置
        self.sh_set = settings
        # 飞船图像与外形
        self.image = self.getImage()
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()
        # 将飞船放在底部中央
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom
        # 移动标志
        self.moving_right = False
        self.moving_left = False

    def update(self):
        if self.moving_right:
            self.rect.centerx += self.sh_set.ship_speed_factor
        if self.moving_left:
            self.rect.centerx -= self.sh_set.ship_speed_factor

    def blitme(self):
        """

        :return:
        """
        # self.changeImageSize()
        self.screen.blit(self.image, self.rect)

    def getImage(self):
        """
        飞船图片
        :return:
        """
        img = pygame.image.load(self.sh_set.ship_image)
        img = pygame.transform.scale(img, self.sh_set.ship_size)
        return img
